﻿@model Jb.Web.ViewModels.ResumeViewModel
@using Jb.Web.Utility;
@using Jb.Common.Extensions;

@{
	String pageTitle = "Edit Resume";
    if (Model != null && Model.ID == 0)
    {             
        pageTitle = "Add New Resume";
    }
    ViewBag.Title = Html.GetPageTitle(pageTitle);
    ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = JobSeekerMenu.Resume;
    bool _HasSaved = ViewData.HasSaved();
    
    int _ResumeToIndex = Jb.Common.DB.NullHandler.GetInt(ViewData[AppConstants.ViewDataKeys.NEW_ID]);
    bool _CanPostResume = true;
    if (!UserInfo.IsJobSeeker || !SessionCache.CurrentUser.JobSeekerInfo.HasProfileCompleted)
    {
        _CanPostResume = false;
    }  
}
<div class="jb-page-heading">
    <h1>@pageTitle</h1>
    <div>Enter necessary information and then click the Save button.</div>
</div>
<div class="jb-page-content">
@*@using (Html.BeginForm()) {*@
@using (Html.BeginForm(null, null, null, FormMethod.Post, new { id = "frmResume", enctype = "multipart/form-data" })){
    @Html.ValidationSummary(true)

	if (Model == null)
    {
        @: @Html.WarningMessageBox("Sorry! Requested Resume was not found for edit.")
    }
	else
	{
        if (_HasSaved) {
            if (_ResumeToIndex > 0)
            {
                <div id="divIndexMessage">@Html.SuccessMessageBox("Congratulations! Your Resume saved successfully. Currently we are indexing your resume, please wait...")</div>            
            }
            else {
                @Html.SuccessMessageBox("Congratulations! Your Resume saved successfully")
            }
        }
        else if (ViewData[AppConstants.ViewDataKeys.SAVED] != null && !_HasSaved)
        {
            @Html.WarningMessageBox("Sorry! we could not save your Resume.")
        }
        if (_CanPostResume)
        {
        
		@Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.JobSeekerID)
        @Html.HiddenFor(model => model.ModifiedOn)
        <input type="hidden" id="hdnResumeToIndex" value="@(_ResumeToIndex)" />
		
		<div class="editor-label">
			@Html.LabelFor(model => model.Title)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.Title, new { @class="jb-long-text"})
			@Html.ValidationMessageFor(model => model.Title)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.FileName)
		</div>
		<div class="editor-field">
            @if (!Model.FileName.IsNullOrEmpty() && String.Compare(Model.FileName, AppConstants.ValueOf.UNKNOWN) != 0) {
                <a href="@Url.ResumeDownloadUrl(Model.ID)" class="btn"><img src="@(Url.GetFileTypeIconUrl(Model.FileName))" alt="" title="" /> @Model.FileName <i class="icon-download-alt"></i></a><br />
            }
			@*@Html..TextBoxFor(model => model.FileName)*@
            @Html.HiddenFor(model => model.FileName)
            <input type="file" value="" name="ResumeFile" id="ResumeFile" class="hidden"/>
            <div class="input-append" style="padding-top:5px;">
                <input type="text" id="FileName_Cosmetic" />
			    <a class="btn" onclick="$('#ResumeFile').click();">Browse</a>
            </div>
            @*<div class="clearfix"></div>*@
			@Html.ValidationMessageFor(model => model.FileName)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.IsDefault)
		</div>
		<div class="editor-field  jb-inline-label">
		    @Html.RadioButtonFor(model => model.IsDefault, "true", new { id = "rdnIsDefault_1" }) <label for="rdnIsDefault_1">Yes</label>
            @Html.RadioButtonFor(model => model.IsDefault, "false", new { id = "rdnIsDefault_0" }) <label for="rdnIsDefault_0">No</label>
		    @Html.ValidationMessageFor(model => model.IsDefault)
	    </div>
		@*<div class="editor-label">
			@Html.LabelFor(model => model.DownloadedCount)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.DownloadedCount)
			@Html.ValidationMessageFor(model => model.DownloadedCount)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.AppearedInSearch)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.AppearedInSearch)
			@Html.ValidationMessageFor(model => model.AppearedInSearch)
		</div>*@
		<div class="editor-label">
			@Html.LabelFor(model => model.SnapShot)
            <div class="jb-label-hint">Resume snap shot is auto generated from your uploaded Resume. 
                Off course, you can change it. Actually it is very <span class="label label-warning">important</span> to change it, 
                because employers usually see this snap shot in your Job Application and Resume listing, before they see the details and download the resume. </div>
		</div>
		<div class="editor-field">
			@Html.TextAreaFor(model => model.SnapShot, new { @class = "jb-long-text" })
			@Html.ValidationMessageFor(model => model.SnapShot)
		</div>		
		<div class="jb-button-container">
			<button class="btn btn-primary" type="submit" data-loading-text="Saving..."><i class="icon-hdd icon-white"></i> Save</button> 
			<a href="@Url.JobSeekerUrl("List", "Resume")" class="btn"><i class="icon-arrow-left"></i> Back to Resume List</a>
		</div>
    
        <!--Modal Popup Section Start-->
        <div id="divIndexingDialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="divPhotoEditModalLabel" aria-hidden="true">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
                <h4 id="myModalLabel">Resume Index Status</h4>
            </div>
            <div class="modal-body jb-inline-label">
                <div>Indexing your resume please wait a moment ...</div>
                <div class="clear"></div>               
            </div>
            <div class="modal-footer">               
                @*<img src="" />*@
            </div>
        </div>
        <!--Modal Popup Section End-->
        }
        else
        {
            @Html.WarningMessageBox("Please complete your job seeker profile first to upload your resume. <br/><br/><a href='/JobSeeker/Home/ProfileEdit' class='btn'><i class='icon-user'></i> Click here</a> to complete your profile.")
        }
    }
}
</div>
@section JavaScriptPlaceHolder
{
@Html.JavaScript("jquery.validate.min.js", Url)
@Html.JavaScript("jquery.validate.unobtrusive.min.js", Url)
<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        //ShowLoadingAnimation(false, 'Indexing your resume,<br/>Please wait a moment ...'); //ShowIndexingModal();        
        var resumeID = parseInt($('#hdnResumeToIndex').val());
        if (resumeID > 0) {
            ShowLoadingAnimation(false, 'Indexing your resume,<br/>Please wait a moment ...');
            Ajax('@(Url.JobSeekerUrl("IndexResume", "Resume"))', 'resumeID=' + resumeID, function (result) {
                HideLoadingAnimation();
                var indexStatus = eval('(' + result + ')');
                var status = parseInt(indexStatus.Status);
                var successMessage = indexStatus.SnapShot.length > 0 ? 'Congratulations! Your Resume indexed successfully for searching. Take a look at the auto generated Resume Snap Shot' : 'Congratulations! Your Resume indexed successfully for searching.';
                if (status == 1)
                    $('#divIndexMessage ').html(SuccessMessageBox(successMessage, ''));
                else if (status == -1)
                    $('#divIndexMessage ').html(WarningMessageBox('Sorry! Requested resume was not found for indexing.', ''));
                else if (status == -3)
                    $('#divIndexMessage ').html(WarningMessageBox('Permission denied, you are not allowed to access this resume.', ''));

                if (indexStatus.SnapShot.length > 0)
                    $('#SnapShot').val(indexStatus.SnapShot);
            });
        }
        // This is the simple bit of jquery to duplicate the hidden field to subfile
        $('#ResumeFile').change(function () {
            $('#FileName_Cosmetic').val($(this).val());
        });
    });
    function ShowIndexingModal() { $('#divIndexingDialog').modal({ show: true, backdrop: false});}
    function HideIndexingModal() { $('#divIndexingDialog').modal('hide'); }
</script>
}

